package com.mjkj.demo.sa_token_role;


import cn.dev33.satoken.stp.StpInterface;
import com.mjkj.demo.constant.Constants;
import com.mjkj.demo.core.redis.RedisCache;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;

/**
 * 自定义权限验证接口扩展
 * @author 19140
 * @date 2023/2/16
 **/
@Component
public class StpInterfaceImpl implements StpInterface {

//    @Resource
//    SystemUsersService systemUsersService;
//
//    @Resource
//    SystemRoleService systemRoleService;

    @Resource
    private RedisCache redisCache;

    /**
     * 返回一个账号所拥有的权限码集合
     */
    @Override
    public List<String> getPermissionList(Object loginId, String loginType) {
//        SystemUsers byId = systemUsersService.getById(Integer.parseInt((String)loginId));
//        if (byId == null){
//            return null;
//        }
//        List<String> cacheList = redisCache.getCacheList(Constants.REDIS_LOGIN_PERMISSION_CODE_KEY+ ":" + byId.getRoleId());
//        return cacheList;
        return null;
    }

    /**
     * 返回一个账号所拥有的角色标识集合 (权限与角色可分开校验)
     */
    @Override
    public List<String> getRoleList(Object loginId, String loginType) {
        String id = loginId.toString();
        System.out.println(id);
        String roleId = redisCache.getCacheObject(Constants.REDIS_LOGIN_ROLE_CODE_KEY + ":" + id);
        return Collections.singletonList(roleId);
    }

}

